<template>
  <div>
    <city-header></city-header>
    <city-search :cities=this.cityList></city-search>
    <city-list :hotCity=this.hotCity
               :cities=this.cityList
               :letter="letter"></city-list>
    <city-alphabet :cities=this.cityList
                   @wordChange="handleChange"></city-alphabet>
  </div>
</template>

<script>
import cityHeader from "@/components/city/header.vue";
import citySearch from "@/components/city/search.vue";
import cityList from "@/components/city/list.vue";
import cityAlphabet from "@/components/city/alphabet.vue";

export default {
  name: "city",
  data() {
    return {
      hotCity: [],
      cityList: {},
      letter: ""
    };
  },
  components: {
    cityHeader,
    citySearch,
    cityList,
    cityAlphabet
  },
  methods: {
    getJsonData() {
      this.$axios.get("api/city.json").then(res => {
        const result = res.data;
        if (result.ret) {
          const data = result.data;
          this.hotCity = data.hotCities;
          this.cityList = data.cities;
          console.log(this.hotCity);
          console.log(this.cityList);
        }
      });
    },
    handleChange(letter) {
      //父子组件传值
      //this.letter = letter;
      console.log(letter);
    }
  },
  mounted() {
    this.getJsonData();
  }
};
</script>

<style lang="stylus" scoped>
</style>
